<template>
	<view class="content poRel">
		<view class="hei20"></view>
		<view class="wid90 mar borRad20" :style="'background: '+theme.main_color+';'" style="height: 214rpx;">
			<view class="wid90 mar">
				<view class="hei86 dis disAl disJuB coFFF" style="border-bottom: 1rpx solid #fff;">
					<view class="foSi30 fowe600">查询时间</view>
					<picker mode="date" fields="month" :value="date1" :end="end" @change="bindDateChange1">
						<view class="dis disAl">
							<view class="foSi25 mar-right10">{{chanfenStr(date1)}}</view>
							<uni-icons type="right" color="#fff" size="30rpx"></uni-icons>
						</view>
					</picker>
				</view>
				<view class="dis disAl" style="justify-content: space-around;height: 126rpx;">
					<view class="textCen coFFF">
						<view class="foSi30" style="line-height: 44rpx;">¥{{tech_price || 0}}</view>
						<view class="foSi20">项目收益</view>
					</view>
					<view class="textCen coFFF">
						<view class="foSi30" style="line-height: 44rpx;">¥{{car_price || 0}}</view>
						<view class="foSi20">车费收益</view>
					</view>
				</view>
			</view>
		</view>
		<view class="mar-top20 wid90 mar bacFFF borRad20 dis disAl disJuC" style="height: 122rpx;">
			<view class="wid90">
				<picker mode="date" fields="month" :end="end" :value="date1" @change="bindDateChange1">
					<view class="dis disAl">
						<view class="fowe600 foSi30">{{chanfenStr(date1)}}</view>
						<view class="mar-left30 dis disAl foSi20" style="color: #7A7A7A;">
							<view>切换</view>
							<uni-icons type="right" size="25rpx"></uni-icons>
						</view>
					</view>
				</picker>
				<view class="foSi20 mar-top10" style="color: #7A7A7A;">实际收入¥{{all_price}}，共{{list.length}}笔订单</view>
			</view>
		</view>
		<scroll-view style="height: calc(100vh - 372rpx);" class="wid100" scroll-y="true" @scrolltolower="lower">
			<view style="height: 1rpx;"></view>
			<wsj v-if="list.length == 0" zs='0'></wsj>
			<block v-for="(item,index) in list" :key="index">
				<view class="mar-top20 wid90 mar bacFFF borRad20">
					<view class="wid90 mar">
						<view class="dis disAl disJuB" style="border-bottom: 1rpx solid #E5E5E5;height: 100rpx;">
							<view class="foSi25 fowe600">订单号：{{item.order_id}}</view>
							<view class="foSi20" style="color: #5B5B5B;">{{item.createtime}}</view>
						</view>
						<view class="mar-top20 dis disAl disJuB">
							<view class="foSi25 fowe600">项目收益</view>
							<view class="foSi30" :style="'color: '+theme.main_color+';'">¥{{item.tech_price}}</view>
						</view>
						<view class="mar-top20 dis disAl disJuB">
							<view class="foSi25 fowe600">车费收益</view>
							<view class="foSi30" :style="'color: '+theme.main_color+';'">¥{{item.car_price}}</view>
						</view>
						<view class="mar-top20 dis disAl disJuB">
							<view class="foSi25 fowe600">实际收益</view>
							<view class="foSi30" style="color: #FF0000;">¥{{item.all_price}}</view>
						</view>
						<view style="height: 40rpx;"></view>
					</view>
				</view>
			</block>
			<view style="height: 50rpx;"></view>
		</scroll-view>
	</view>
</template>

<script>
	import wsj from '../common/w_sj.vue'
	export default {
		components: {
			wsj
		},
		data() {
			return {
				url: this.global.url,
				timer: null,
				sousuo: '',
				xuan: 0,
				last_page: 0,
				page: 1,
				list: [],
				date: '',
				date1: '',
				end: '',
				all_price: '', //总计收益
				tech_price: '', //项目收益
				car_price: '' ,//车费收益
				theme: null
			}
		},
		onLoad() {
			this.theme = uni.getStorageSync('theme')
			this.date1 = this.dateFormat()
			this.end = this.dateFormat()
			this.getList()
		},
		methods: {
			dateFormat(time) {
				let date = new Date();
				let year = date.getFullYear();
				// 在日期格式中，月份是从0开始的，因此要加0，使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
				let month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
				let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
				let hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
				let minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
				let seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
				// 拼接
				// return year+"-"+month;
				return year + "-" + month;
			},
			chanfenStr(val){
				return val.split("-")[0]+'年'+val.split("-")[1]+'月'
			},
			bindDateChange1: function(e) {
				this.date1 = e.detail.value
				this.page = 1
				this.getList()
			},
			bindDateChange: function(e) {
				this.date = e.detail.value
			},
			lower(e) {
				if(this.last_page > this.page){
					this.page++
					this.getList()
				}
			},
			getList(){
				var that = this;
				uni.request({
					url: that.global.url + 'api/qianyu_smfw/tech/splitting_details',
					method: "POST",
					header: {
						'site-id': that.global.site_id, //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						page: that.page,
						tech_id: uni.getStorageSync('tech_id'),
						start_time: that.date1
					},
					success(res) {
						let result = res.data
						if (result.code == 1) {
							that.last_page = result.data.data.last_page
							that.all_price = result.data.all_price//总计收益
							that.tech_price = result.data.tech_price//项目收益
							that.car_price = result.data.car_price//车费收益
							if(that.page == 1){
								that.list = result.data.data.data
							}else{
								that.list = that.list.concat(result.data.data)
							}
						}else{
							uni.showToast({
								title: result.msg,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'error',
								//显示持续时间为 2秒
								duration: 2000
							}) 
						}
					}
				})
				
			},
			tiaozhuan(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	.content {
		min-height: 100vh;
		background-color: #F3F1F1;
	}
	.xia{
		height: 1rpx;
		background-color: #E5E5E5;
	}
	.butt1{
		width: 120rpx;
		height: 42rpx;
		color: #8A8A8A;
		border: 1rpx solid #8A8A8A;
		border-radius: 8rpx;
	}
	.butt2{
		width: 120rpx;
		height: 42rpx;
		background-color: #00AD27;
		border: 1rpx solid #00AD27;
		border-radius: 8rpx;
	}
</style>